/**
 * @file 工具函数统一入口
 * @description 提供多种导入方式的统一工具函数库
 * @date 2024-07-02
 */

// ==================== 命名空间导出（推荐方式）====================
// 导出各个模块的命名空间
export * as http from './http';
export * as format from './format';
export * as system from './system';
export * as helpers from './helpers';
export * as map from './map';

// ==================== 模块对象导出 ====================
import * as httpModule from './http';
import * as formatModule from './format';
import * as systemModule from './system';
import * as helpersModule from './helpers';
import * as mapModule from './map';

/**
 * 工具函数统一对象
 * 使用方式: import utils from '@/utils';
 */
const utils = {
  http: httpModule,
  format: formatModule,
  system: systemModule,
  helpers: helpersModule,
  map: mapModule
};

export default utils;

// ==================== 状态管理和类型导出 ====================
/**
 * 导出状态管理相关的store
 * 使用方式: import { stores } from '@/utils';
 */
export const stores = {
  device: require('@/stores/modules/device'),
  track: require('@/stores/modules/track'),
  location: require('@/stores/modules/location')
};

/**
 * 导出常用类型定义
 * 使用方式: import { types } from '@/utils';
 */
export const types = {
  // 基础类型
  ...require('@/types'),
  // 设备类型
  device: require('@/types/device'),
  // 状态类型
  state: require('@/types/state')
};

// ==================== 向后兼容导出 ====================
/**
 * @deprecated 以下导出保留用于向后兼容，新代码请使用命名空间导入
 * 例如: import { format } from '@/utils'; format.formatDate();
 */

// 格式化工具
export { 
  formatDate, formatDateTime, formatTime, timestampToDate, 
  getDaysBetween, formatDuration 
} from './format/date';

export { 
  formatDistance, formatSpeed, formatCoordinate 
} from './format/distance';

export { 
  formatFileSize, formatPercent 
} from './format/filesize';

// 地理工具
export { 
  getDistance, calculateTotalDistance, calculateAverageSpeed, isPointInPolygon 
} from './format/geo';

// 通用工具
export { 
  debounce, throttle, deepClone, generateUniqueId, getValueByPath 
} from './helpers/common';

// 系统工具
export { logger } from './system/logger';
export { initFrontendMonitor } from './system/monitor';

// HTTP工具
export { 
  request, get, post, put, del 
} from './http/request';

// 导出Vue API（保持向后兼容）
export * from 'vue';

// 保持原有类型导出（向后兼容）
export * from '@/stores/modules/device';
export * from '@/stores/modules/track';
export * from '@/stores/modules/location';

export type { User, TrackPoint, TrackData, Device, ApiResponse, PagedData, QueryParams } from '@/types';
export type { DeviceLocation, DeviceStats, DeviceAttribute } from '@/types/device';
export type {
  UserState,
  DeviceState,
  TrackState,
  SettingsState,
  DashboardState,
  LocationState
} from '@/types/state'; 